<template>
  <div>
    <div class="top">
      <el-form :inline="true">
        <el-form-item label="设备编号：">
          <el-input v-model="data.innerCode" placeholder="请输入" style="width:180px" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="inquire">
            <i class="el-icon-search" />
            查询</el-button>
          <el-button @click="fun">测试</el-button>
        </el-form-item>
      </el-form>
      <svg class="sousuo" />
    </div>
    <div class="list">
      <!-- 列表 -->
      <el-table :data="list">
        <el-table-column type="index" label="序号">
          <template scope="scope">
            <span>{{ (data.pageIndex-1)*data.pageSize+scope.$index+1 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="设备编号">
          <template v-slot="{ row }">
            <span>{{ row ?.innerCode }}</span>
          </template>
        </el-table-column>
        <el-table-column label="设备型号">
          <template v-slot="{ row }">
            <span>{{ row?.type?.name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="详细地址">
          <template v-slot="{ row }">
            <span>{{ row?.node?.name }}</span>
          </template>

        </el-table-column>
        <el-table-column label="运营状态">
          <template v-slot="{ row }">
            <span>{{ vmStatuslist[ row.vmStatus ] }}</span>
          </template>
        </el-table-column>
        <el-table-column width="280px" label="设备状态">
          <template>
            <div class="sbzt">
              <div class="lixian">离线</div>
              <div class="huodao">货道</div>
              <div class="huodao">传动轴</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template v-slot="{ row }">
            <el-button type="text" @click="wyckxq(row)">查看详情</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-row type="flex" style="height:60px" align="middle" justify="space-between">
        <span class="record">共{{ totalCount }}条记录 第{{ data.pageIndex }}/ {{ totalPage }} 页</span>
        <el-pagination
          :page-size="data.pagesize"
          :current-page="data.pageIndex"
          layout="prev,  next"
          :total="+totalCount"
          prev-text="上一页"
          next-text="下一页"
          @current-change="changePage"
        />
      </el-row>
    </div>
    <el-dialog
      title="设备详情"
      :visible.sync="dialogShow"
      width="45%"
      :before-close="handleClose"
    >
      <div class="dialogtop">
        <span>销售量：  <span class="blue">{{ bodylist.xsl }}个</span></span>
        <span>销售额：  <span class="blue">{{ bodylist. xse / 100 }} 元</span></span>
        <span>补货次数：<span class="blue">{{ bodylist.bhcs }}次</span></span>
        <span>补货次数：<span class="blue">{{ bodylist.wxcs }}次</span></span>
      </div>
      <p>商品销量（月）</p>
      <el-row>
        <el-col v-for="(item, index) in bodylist.xpxl" :key="index" :span="6">
          <div class="titless">
            {{ item.skuName }}:{{ item.count }}
          </div>
        </el-col>

      </el-row>
    </el-dialog>
  </div>
</template>

<script>
import { GETbuhuocishu, getEquipment, GETshangpinxiaoliang, GETweixiucishu, GETxiaoshouer, GETxiaoshouliang } from '@/api/department'

export default {
  name: 'Department2',
  data() {
    return {
      // 详情列表弹框
      dialogShow: false,
      // 获取列表数据
      data: {
        pageIndex: 1,
        pageSize: 10,
        status: '',
        innerCode: ''
      },
      // 总数据
      totalCount: '',
      // 总页数
      totalPage: '',
      // 列表数据
      list: [],
      // 售货机状态映射表
      vmStatuslist: {
        0: '未投放',
        1: '运营',
        3: '撤机'
      },
      // 查看销售量,销售额 接口数据
      particularsList: {
        start: '',
        end: '',
        innerCode: ''
      },
      // 查看维修，补货，商品销量
      partist: {
        start: '',
        end: '',
        innerCode: ''
      },
      // 查看维修 补货 商品销量 data
      pardata: {
        vmType: null,
        nodeId: null,
        createUserId: null
      },
      // 查看详情数据
      bodylist: {
        xsl: '',
        xse: '',
        bhcs: '',
        wxcs: '',
        xpxl: []
      }
    }
  },
  created() {
    // 页面列表
    this.getEquipmentList()
  },
  methods: {
    // 关闭弹窗
    handleClose() {
      this.dialogShow = false
    },
    // 分页
    changePage(newPage) {
      // console.log(newPage)
      this.data.pageIndex = newPage
      // console.log(this.data)
      this.getEquipmentList()
    },
    // 获取列表数据
    async getEquipmentList() {
      const res = await getEquipment(this.data)
      this.list = res.currentPageRecords
      this.totalCount = res.totalCount
      this.totalPage = res.totalPage
      console.log(this.list)
    },
    // 查询重新渲染页面
    inquire() {
      this.getEquipmentList()
    },
    async wyckxq(row) {
      this.particularsList.innerCode = row.innerCode
      this.particularsList.start = this.$dayjs(row.node.createTime).format('YYYY-MM-DD HH:mm:ss')
      this.particularsList.end = this.$dayjs(row.node.updateTime).format('YYYY-MM-DD HH:mm:ss')
      this.partist.innerCode = row.innerCode
      this.partist.start = this.$dayjs().format('YYYY-MM-DD')
      this.partist.end = this.$dayjs(row.node.createTime).format('YYYY-MM-DD')
      // this.partist.start = this.$dayjs(row.node.createTime).format('YYYY-MM-DD')
      // this.partist.end = this.$dayjs(row.node.updateTime).format('YYYY-MM-DD')
      this.pardata.vmType = row.vmType
      this.pardata.nodeId = row.nodeId
      this.pardata.createUserId = row.createUserId
      // console.log(this.particularsList.end)
      this.bodylist.xsl = await GETxiaoshouer(this.particularsList)
      this.bodylist.xse = await GETxiaoshouliang(this.particularsList)
      this.bodylist.bhcs = await GETbuhuocishu(this.partist)
      this.bodylist.wxcs = await GETweixiucishu(this.partist)
      this.bodylist.xpxl = await GETshangpinxiaoliang(this.partist)
      console.log(row)
      this.dialogShow = true
    },
    fun() {
      const aa = this.$dayjs(1).format('YYYY-MM-DD')
      console.log(aa)
    }
  }
}
</script>

<style  lang='scss' scoped>
.selected{
position: relative;
    width: 134px;
    height: 134px;
    padding-top: 16px;
    background-color: #f6f7fb;
    -webkit-box-shadow: 0 2px 4px 0 rgba(0,0,0,.06);
    box-shadow: 0 2px 4px 0 rgba(0,0,0,.06);
    border-radius: 4px;
    text-align: center;
    cursor: pointer;
}
 .top{
    height: 80px;
    margin: 20px;
    padding: 18px;
    background-color: #fff;
  }
    .list{
    padding: 18px;
    margin: 20px;
    background-color: #fff;
   }
    ::v-deep.el-pagination .btn-next{
  background-color: #d5ddf8 !important;
  width: 70px;
  height: 30px;
  text-align: center;
  border-radius: 3px;
   margin: 10px;
}

::v-deep.el-pagination .btn-prev{
  background-color: #d5ddf8 !important;
  width: 70px;
  height: 30px;
  text-align: center;
  border-radius: 3px;
  margin: 10px;
}
.record{
  color: #dbdfe5;
}
.sbzt{
  display: flex;
  .lixian{
    padding: 2px 15px;
    border-radius: 20px;
    background-color: #ffba2b;
    color: #fff;
  }
  .huodao{
     padding: 2px 15px;
    border-radius: 20px;
    background-color: #48d698;
    color: #fff;
  }
}
.dialogtop{
  width: 100%;
  display: flex;
  justify-content: space-evenly;
  align-content: center;
  background-color: #f4f6fb;
  padding: 20px 0;
  margin-bottom: 10px;
  .blue{
    color: #87a2fe;
  }
}
.titless{
  padding: 10px;
  border: 1px solid #d8dde3;
}
</style>
